﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Web.Caching;
using System.Web;
using System.Web.SessionState;

namespace Web
{
    public class common
    {
        public static double numTotol = 0;//保存储户的本金和利息总和

        /// <summary>
        /// 判断Session超时
        /// </summary>
        public static void IsLogin()
        {
            object um = HttpContext.Current.Session["ID"];// 查询ID的Session值是否存在
            object cook = HttpContext.Current.Request.Cookies["LoginInfo"];
            bool ok = false;
            try
            {
                if (um != null)
                {
                    ok = true;
                }
                else//Cookie重新写入Session  
                {
                    if (HttpContext.Current.Request.Cookies["LoginInfo"] != null)
                    {
                      
                        int User_ID = int.Parse(HttpContext.Current.Request.Cookies["LoginInfo"]["ID"].ToString());
                        StringBuilder strSql = new StringBuilder();
                        strSql.Append(" SELECT ID, UserGroup_ID,WB_ID,strRealName,strLoginName");
                        strSql.Append(" FROM dbo.Users");
                        strSql.Append(" WHERE ID=@ID");
                        SqlParameter parameter = new SqlParameter("@ID", System.Data.SqlDbType.Int, 4);
                        parameter.Value = User_ID.ToString();
                        System.Data.DataTable dtAccount = SQLHelper.ExecuteDataTable(strSql.ToString(), parameter);
                        if (dtAccount != null && dtAccount.Rows.Count != 0)
                        {
                            HttpContext.Current.Session.Clear();
                            HttpContext.Current.Session["WB_ID"] = dtAccount.Rows[0]["WB_ID"].ToString();//该用户所在的网点ID
                            HttpContext.Current.Session["UserGroup_ID"] = dtAccount.Rows[0]["UserGroup_ID"].ToString();//该用户所在的用户组ID
                            string UserGroupName = SQLHelper.ExecuteScalar("  SELECT strName FROM dbo.UserGroup WHERE ID=" + dtAccount.Rows[0]["UserGroup_ID"].ToString()).ToString();
                            HttpContext.Current.Session["UserGroup_Name"] = UserGroupName;
                            HttpContext.Current.Session["ID"] = dtAccount.Rows[0]["ID"].ToString();//用户ID
                            HttpContext.Current.Session["strLoginName"] = dtAccount.Rows[0]["strLoginName"].ToString();//用户登录名
                            HttpContext.Current.Session["strRealName"] = dtAccount.Rows[0]["strRealName"].ToString();
                        }
                     
                        ok = true;
                    }
                    else
                    {
                        ok = false;
                    }
                }
            }
            catch (SystemException ex)
            {
               // HyDebug.WriteToDoc("110:" + ex.Message);//HyDebug可以用直接写入文本的方式在网站发布之后查看我们的调试信息
                ok = false;
            }
            if (ok == false)
            {
              
                HttpContext.Current.Response.Write("<script>top.window.location.href='/default.aspx';</script>");
                HttpContext.Current.Response.End();
            }

        }

        /// <summary>
        /// 查询用户的菜单权限
        /// </summary>
        /// <param name="UserGroupName">角色组名称</param>
        /// <param name="UserID">用户编号</param>
        /// <param name="MenuID">菜单编号</param>
        /// <param name="MenuType">菜单类型</param>
        /// <returns></returns>
        public static bool GetAuthority(object UserGroupName,object UserID,  object MenuID,object MenuType)
        {
            StringBuilder  strSql = new StringBuilder ();
            strSql.Append("SELECT TOP 1 menuList FROM dbo.UserMenu WHERE 1=1");
            if (UserGroupName.ToString() == "单位管理员") {
                return true;
            }
            if (UserGroupName.ToString() == "营业员")
            {
                strSql.Append( " and numtype=2 ");
            }
            else
            {
                strSql.Append(" and numtype=1 ");
            }
            strSql.Append(" and UserID="+UserID.ToString());
            object objmenu = SQLHelper.ExecuteScalar(strSql.ToString());
            if (objmenu == null || objmenu.ToString() == "")
            {
                return false;
            }
            Dictionary<string, string> dicmenu = new Dictionary<string, string>();//key：菜单ID，value：菜单值
            string[] menuArray = objmenu.ToString().Split('|');
            for (int i = 0; i < menuArray.Length; i++)
            {
                string[] menuArrayChild = menuArray[i].Split(':');
                dicmenu.Add(menuArrayChild[0], menuArrayChild[1]);
            }
            if(dicmenu.ContainsKey(MenuID.ToString()))
            {
                string strValue = dicmenu[MenuID.ToString()];
                if (strValue.Contains(MenuType.ToString()))
                {
                    return true;
                }
                else {
                    return false;
                }
            }
            else{
                return false;
            }



        }

        #region 页面显示的利息计算

        public static string GetDay(object date)
        {
            DateTime t1 = Convert.ToDateTime(date);
            TimeSpan ts = DateTime.Now.Subtract(t1);
            int numday = Convert.ToInt32(Math.Floor((decimal)ts.TotalDays));
            return numday.ToString();

        }

        public static string GetLiXi(object obj)
        {

            string strReturn = "";
            double numLiXi = 0;
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" select B.ISRegular,B.InterestType,A.StorageNumber,A.Price_ShiChang,A.StorageDate,B.numStorageDate");
            strSql.Append(" FROM dbo.Dep_StorageInfo A INNER JOIN dbo.StorageTime B ON A.TimeID=B.ID");
            strSql.Append(" WHERE A.ID=" + obj.ToString());

            DataTable dt = SQLHelper.ExecuteDataTable(strSql.ToString());
            if (dt != null && dt.Rows.Count != 0)
            {
                bool ISRegular = Convert.ToBoolean(dt.Rows[0]["ISRegular"]);//是否是定期类型
                int InterestType = Convert.ToInt32(dt.Rows[0]["InterestType"]);//利息计算方式
                double StorageNumber = Convert.ToDouble(dt.Rows[0]["StorageNumber"]);//存储数量
                double Price_ShiChang = Convert.ToDouble(dt.Rows[0]["Price_ShiChang"]);//存入时的市场价

                DateTime StorageDate = Convert.ToDateTime(dt.Rows[0]["StorageDate"]);//存入日期
                TimeSpan ts_Storage = DateTime.Now.Subtract(StorageDate);
                int numStorageDate = Convert.ToInt32(dt.Rows[0]["numStorageDate"]);//约定存储时间

                switch (InterestType)
                {
                    case 1://按月结息方式
                        if (ISRegular)//是定期（入股类型）
                        {
                            numLiXi = GetLiXi_RuGu(obj.ToString(), StorageNumber);
                            if (ts_Storage.TotalDays >= numStorageDate)
                            {
                                strReturn = "<span style='color:Blue;'>￥" + Math.Round(numLiXi, 2).ToString() + "</span>";
                            }
                            else
                            {
                                strReturn = "<span style='font-size:12px;color:Red'>￥" + Math.Round(numLiXi, 2).ToString() + "(未到期)</span>";
                            }
                        }
                        else
                        { //不是定期(付息类型)
                            numLiXi = GetLiXi_FuXi(obj.ToString(), StorageNumber);
                            strReturn = "<span style='color:Blue;'>￥" + Math.Round(numLiXi, 2).ToString() + "</span>";
                        }
                        break;
                    case 2://按市场价结息方式
                        numLiXi = GetLiXi_FenHong(obj.ToString(), StorageNumber);
                        if (ts_Storage.TotalDays >= numStorageDate)
                        {
                            strReturn = "<span style='color:Blue;'>￥" + Math.Round(numLiXi, 2).ToString() + "</span>";
                        }
                        else
                        {
                            strReturn = "<span style='font-size:12px;color:Red'>￥" + Math.Round(numLiXi, 2).ToString() + "(未到期)</span>";
                        }
                        break;
                    case 3:
                        numLiXi = GetLiXi_DingQi(obj.ToString(), StorageNumber);
                        if (ts_Storage.TotalDays >= numStorageDate)
                        {
                            strReturn = "<span style='color:Blue;'>￥" + Math.Round(numLiXi, 2).ToString() + "</span>";
                        }
                        else
                        {
                            strReturn = "<span style='font-size:12px;color:Red'>￥" + Math.Round(numLiXi, 2).ToString() + "(未到期)</span>";
                        }
                        break;
                }
                numTotol = numTotol + StorageNumber * Price_ShiChang + numLiXi;
            }
            numTotol = Math.Round(numTotol, 2);
            return strReturn;
        }


        /// <summary>
        /// 计算利息 活期付息类型
        /// </summary>
        /// <param name="Dep_SID">储户存储单编号</param>
        /// <param name="StorageNumber">用于计算利息的存储数量</param>
        /// <returns></returns>
        public static double GetLiXi_FuXi(string Dep_SID, double StorageNumber)
        {
            double numLiXi = 0;
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT A.StorageDate,A.InterestDate,A.CurrentRate, A.Price_DaoQi, A.Price_ShiChang,B.numStorageDate");
            strSql.Append(" FROM dbo.Dep_StorageInfo A INNER JOIN dbo.StorageTime B ON A.TimeID=B.ID");
            strSql.Append(" WHERE A.ID=" + Dep_SID);
            DataTable dt = SQLHelper.ExecuteDataTable(strSql.ToString());
            if (dt != null && dt.Rows.Count != 0)
            {


                DateTime StorageDate = Convert.ToDateTime(dt.Rows[0]["StorageDate"]);//存入日期
                DateTime InterestDate = Convert.ToDateTime(dt.Rows[0]["InterestDate"]);//上一次的取利息日期
                int numStorageDate = Convert.ToInt32(dt.Rows[0]["numStorageDate"]);//约定存储时间
                TimeSpan ts_Storage = DateTime.Now.Subtract(StorageDate);
                TimeSpan ts_Interest = DateTime.Now.Subtract(InterestDate);
                double CurrentRate = Convert.ToDouble(dt.Rows[0]["CurrentRate"]);//约定月利率
                double Price_ShiChang = Convert.ToDouble(dt.Rows[0]["Price_ShiChang"]);//存入时的市场价
                double Price_DaoQi = Convert.ToDouble(dt.Rows[0]["Price_DaoQi"]);//到期价
                //获取利息计算方式
                int InterestDay = Convert.ToInt32( ts_Interest.TotalDays);//可以计算利息的总天数
                int InterestType = Convert.ToInt32(GetWBAuthority()["InterestType"]);//1：按天结息  2：按月结息
                if (InterestType == 2)
                {
                    InterestDay = InterestDay - InterestDay % 30;
                }

                numLiXi = StorageNumber * CurrentRate * InterestDay / (double)30;
            }
            return numLiXi;
        }


        /// <summary>
        /// 计算利息 活期 分红类型
        /// </summary>
        /// <param name="Dep_SID">储户存储单编号</param>
        /// <param name="StorageNumber">用于计算利息的存储数量</param>
        /// <returns></returns>
        public static double GetLiXi_FenHong(string Dep_SID, double StorageNumber)
        {
            double numLiXi = 0;
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT A.StorageDate,A.InterestDate,A.CurrentRate, A.Price_DaoQi, A.Price_ShiChang,B.numStorageDate");
            strSql.Append(" FROM dbo.Dep_StorageInfo A INNER JOIN dbo.StorageTime B ON A.TimeID=B.ID");
            strSql.Append(" WHERE A.ID=" + Dep_SID);
            DataTable dt = SQLHelper.ExecuteDataTable(strSql.ToString());
            if (dt != null && dt.Rows.Count != 0)
            {


                DateTime StorageDate = Convert.ToDateTime(dt.Rows[0]["StorageDate"]);//存入日期
                DateTime InterestDate = Convert.ToDateTime(dt.Rows[0]["InterestDate"]);//上一次的取利息日期
                int numStorageDate = Convert.ToInt32(dt.Rows[0]["numStorageDate"]);//约定存储时间
                TimeSpan ts_Storage = DateTime.Now.Subtract(StorageDate);
                TimeSpan ts_Interest = DateTime.Now.Subtract(InterestDate);
                double CurrentRate = Convert.ToDouble(dt.Rows[0]["CurrentRate"]);//约定月利率
                double Price_ShiChang = Convert.ToDouble(dt.Rows[0]["Price_ShiChang"]);//存入时的市场价
                double Price_DaoQi = Convert.ToDouble(dt.Rows[0]["Price_DaoQi"]);//到期价


                if (ts_Storage.TotalDays < numStorageDate)//分红类型未到约定的存期
                {
                    numLiXi = 0;
                }
                else
                {
                    //计算当前的市场价格
                    StringBuilder strSqlShiChang = new StringBuilder();
                    strSqlShiChang.Append(" SELECT B.Price_ShiChang,B.EarningRate");
                    strSqlShiChang.Append(" FROM dbo.Dep_StorageInfo A INNER JOIN dbo.StorageRate B ON A.StorageRateID=B.ID");
                    strSqlShiChang.Append(" WHERE A.ID=" + Dep_SID);
                    DataTable dtShiChang = SQLHelper.ExecuteDataTable(strSqlShiChang.ToString());
                    if (dtShiChang != null && dtShiChang.Rows.Count != 0)
                    {
                        double Price_JieCun = Convert.ToDouble(dtShiChang.Rows[0]["Price_ShiChang"]);
                        int EarningRate = Convert.ToInt32(dtShiChang.Rows[0]["EarningRate"]);
                        if (Price_JieCun >= Price_ShiChang)//到期的结存价格比现在的市场价高(存储产品盈利的时候 按照分红比例分红)
                        {
                            numLiXi = (Price_JieCun - Price_ShiChang) * StorageNumber * EarningRate / (double)100;
                        }
                        else//存储产品价格降低的时候由储户承担全部损耗
                        {
                            numLiXi = -(Price_ShiChang - Price_JieCun) * StorageNumber;
                        }
                    }
                }


                ////计算当前的市场价格
                //StringBuilder strSqlShiChang = new StringBuilder();
                //strSqlShiChang.Append(" SELECT B.Price_ShiChang,B.EarningRate");
                //strSqlShiChang.Append(" FROM dbo.Dep_StorageInfo A INNER JOIN dbo.StorageRate B ON A.StorageRateID=B.ID");
                //strSqlShiChang.Append(" WHERE A.ID=" + Dep_SID);
                //DataTable dtShiChang = SQLHelper.ExecuteDataTable(strSqlShiChang.ToString());
                //if (dtShiChang != null && dtShiChang.Rows.Count != 0)
                //{
                //    double Price_JieCun = Convert.ToDouble(dtShiChang.Rows[0]["Price_ShiChang"]);
                //    int EarningRate = Convert.ToInt32(dtShiChang.Rows[0]["EarningRate"]);
                //    if (Price_JieCun >= Price_ShiChang)//到期的结存价格比现在的市场价高(存储产品盈利的时候 按照分红比例分红)
                //    {
                //        numLiXi = (Price_JieCun - Price_ShiChang) * StorageNumber * EarningRate / (double)100;
                //    }
                //    else//存储产品价格降低的时候由储户承担全部损耗
                //    {
                //        numLiXi = -(Price_ShiChang - Price_JieCun) * StorageNumber;
                //    }
                //}

            }
            return numLiXi;
        }

        /// <summary>
        /// 计算利息 定期类型(入股)
        /// </summary>
        /// <param name="Dep_SID">储户存储单编号</param>
        /// <param name="StorageNumber">用于计算利息的存储数量</param>
        /// <returns></returns>
        public static double GetLiXi_RuGu(string Dep_SID, double StorageNumber)
        {
            double numLiXi = 0;
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT A.StorageDate,A.InterestDate,A.CurrentRate, A.Price_DaoQi, A.Price_ShiChang,B.numStorageDate");
            strSql.Append(" FROM dbo.Dep_StorageInfo A INNER JOIN dbo.StorageTime B ON A.TimeID=B.ID");
            strSql.Append(" WHERE A.ID=" + Dep_SID);
            DataTable dt = SQLHelper.ExecuteDataTable(strSql.ToString());
            if (dt != null && dt.Rows.Count != 0)
            {


                DateTime StorageDate = Convert.ToDateTime(dt.Rows[0]["StorageDate"]);//存入日期
                DateTime InterestDate = Convert.ToDateTime(dt.Rows[0]["InterestDate"]);//上一次的取利息日期
                int numStorageDate = Convert.ToInt32(dt.Rows[0]["numStorageDate"]);//约定存储时间
                TimeSpan ts_Storage = DateTime.Now.Subtract(StorageDate);
                TimeSpan ts_Interest = DateTime.Now.Subtract(InterestDate);
                double CurrentRate = Convert.ToDouble(dt.Rows[0]["CurrentRate"]);//约定月利率
                double Price_ShiChang = Convert.ToDouble(dt.Rows[0]["Price_ShiChang"]);//存入时的市场价
                double Price_DaoQi = Convert.ToDouble(dt.Rows[0]["Price_DaoQi"]);//到期价

                //获取利息计算方式
                int InterestDay = Convert.ToInt32(ts_Interest.TotalDays);//可以计算利息的总天数
                int InterestType = Convert.ToInt32(GetWBAuthority()["InterestType"]);//1：按天结息  2：按月结息
                if (InterestType == 2)
                {
                    InterestDay = InterestDay - InterestDay % 30;
                }

                numLiXi = StorageNumber * CurrentRate * InterestDay / (double)30;

            }
            return numLiXi;
        }

        /// <summary>
        /// 计算利息 活期付息类型
        /// </summary>
        /// <param name="Dep_SID">储户存储单编号</param>
        /// <param name="StorageNumber">用于计算利息的存储数量</param>
        /// <returns></returns>
        public static string GetPolicy_FuXi(string Dep_SID, double StorageNumber)
        {
            string strReturn = "当前产品存期类型：付息,";//返回信息
           
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT A.StorageDate,A.InterestDate,A.CurrentRate, A.Price_DaoQi, A.Price_ShiChang,B.numStorageDate");
            strSql.Append(" FROM dbo.Dep_StorageInfo A INNER JOIN dbo.StorageTime B ON A.TimeID=B.ID");
            strSql.Append(" WHERE A.ID=" + Dep_SID);
            DataTable dt = SQLHelper.ExecuteDataTable(strSql.ToString());
            if (dt != null && dt.Rows.Count != 0)
            {


                DateTime StorageDate = Convert.ToDateTime(dt.Rows[0]["StorageDate"]);//存入日期
                DateTime InterestDate = Convert.ToDateTime(dt.Rows[0]["InterestDate"]);//上一次的取利息日期
                int numStorageDate = Convert.ToInt32(dt.Rows[0]["numStorageDate"]);//约定存储时间
                TimeSpan ts_Storage = DateTime.Now.Subtract(StorageDate);
                TimeSpan ts_Interest = DateTime.Now.Subtract(InterestDate);
                double CurrentRate = Convert.ToDouble(dt.Rows[0]["CurrentRate"]);//约定月利率
                double Price_ShiChang = Convert.ToDouble(dt.Rows[0]["Price_ShiChang"]);//存入时的市场价
                double Price_DaoQi = Convert.ToDouble(dt.Rows[0]["Price_DaoQi"]);//到期价


                strReturn += "市场价："+Price_ShiChang+"，月利率："+CurrentRate;
            }
            return strReturn;
        }


        /// <summary>
        /// 计算利息 活期 分红类型
        /// </summary>
        /// <param name="Dep_SID">储户存储单编号</param>
        /// <param name="StorageNumber">用于计算利息的存储数量</param>
        /// <returns></returns>
        public static string GetPolicy_FenHong(string Dep_SID, double StorageNumber)
        {
            string strReturn = "当前产品存期类型：分红,";//返回信息
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT A.StorageDate,A.InterestDate,A.CurrentRate, A.Price_DaoQi, A.Price_ShiChang,B.numStorageDate");
            strSql.Append(" FROM dbo.Dep_StorageInfo A INNER JOIN dbo.StorageTime B ON A.TimeID=B.ID");
            strSql.Append(" WHERE A.ID=" + Dep_SID);
            DataTable dt = SQLHelper.ExecuteDataTable(strSql.ToString());
            if (dt != null && dt.Rows.Count != 0)
            {


                DateTime StorageDate = Convert.ToDateTime(dt.Rows[0]["StorageDate"]);//存入日期
                DateTime InterestDate = Convert.ToDateTime(dt.Rows[0]["InterestDate"]);//上一次的取利息日期
                int numStorageDate = Convert.ToInt32(dt.Rows[0]["numStorageDate"]);//约定存储时间
                TimeSpan ts_Storage = DateTime.Now.Subtract(StorageDate);
                TimeSpan ts_Interest = DateTime.Now.Subtract(InterestDate);
                double CurrentRate = Convert.ToDouble(dt.Rows[0]["CurrentRate"]);//约定月利率
                double Price_ShiChang = Convert.ToDouble(dt.Rows[0]["Price_ShiChang"]);//存入时的市场价
                double Price_DaoQi = Convert.ToDouble(dt.Rows[0]["Price_DaoQi"]);//到期价


                if (ts_Storage.TotalDays < numStorageDate)//分红类型未到约定的存期
                {
                    strReturn += "未到期，存入价："+Price_ShiChang;
                }
                else
                {
                    //计算当前的市场价格
                    StringBuilder strSqlShiChang = new StringBuilder();
                    strSqlShiChang.Append(" SELECT B.Price_ShiChang,B.EarningRate");
                    strSqlShiChang.Append(" FROM dbo.Dep_StorageInfo A INNER JOIN dbo.StorageRate B ON A.StorageRateID=B.ID");
                    strSqlShiChang.Append(" WHERE A.ID=" + Dep_SID);
                    DataTable dtShiChang = SQLHelper.ExecuteDataTable(strSqlShiChang.ToString());
                    if (dtShiChang != null && dtShiChang.Rows.Count != 0)
                    {

                        strReturn += "已到期，存入价：" + Price_ShiChang + ",市场价：" + dtShiChang.Rows[0]["Price_ShiChang"].ToString();
                    }
                }


          

            }
            return strReturn;
        }

        /// <summary>
        /// 计算利息 定期类型(入股)
        /// </summary>
        /// <param name="Dep_SID">储户存储单编号</param>
        /// <param name="StorageNumber">用于计算利息的存储数量</param>
        /// <returns></returns>
        public static string GetPolicy_RuGu(string Dep_SID, double StorageNumber)
        {
            string strReturn = "当前产品存期类型：入股";//返回信息
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT A.StorageDate,A.InterestDate,A.CurrentRate, A.Price_DaoQi, A.Price_ShiChang,B.numStorageDate");
            strSql.Append(" FROM dbo.Dep_StorageInfo A INNER JOIN dbo.StorageTime B ON A.TimeID=B.ID");
            strSql.Append(" WHERE A.ID=" + Dep_SID);
            DataTable dt = SQLHelper.ExecuteDataTable(strSql.ToString());
            if (dt != null && dt.Rows.Count != 0)
            {


                DateTime StorageDate = Convert.ToDateTime(dt.Rows[0]["StorageDate"]);//存入日期
                DateTime InterestDate = Convert.ToDateTime(dt.Rows[0]["InterestDate"]);//上一次的取利息日期
                int numStorageDate = Convert.ToInt32(dt.Rows[0]["numStorageDate"]);//约定存储时间
                TimeSpan ts_Storage = DateTime.Now.Subtract(StorageDate);
                TimeSpan ts_Interest = DateTime.Now.Subtract(InterestDate);
                double CurrentRate = Convert.ToDouble(dt.Rows[0]["CurrentRate"]);//约定月利率
                double Price_ShiChang = Convert.ToDouble(dt.Rows[0]["Price_ShiChang"]);//存入时的市场价
                double Price_DaoQi = Convert.ToDouble(dt.Rows[0]["Price_DaoQi"]);//到期价

                strReturn += "，市场价："+Price_ShiChang+"月利率："+CurrentRate;
            }
            return strReturn;
        }

        /// <summary>
        /// 计算利息 定期类型(1年 2年)
        /// </summary>
        /// <param name="Dep_SID">储户存储单编号</param>
        /// <param name="StorageNumber">用于计算利息的存储数量</param>
        /// <returns></returns>
        public static double GetLiXi_DingQi(string Dep_SID, double StorageNumber)
        {
            double numLiXi = 0;
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT A.StorageDate,A.InterestDate,A.CurrentRate, A.Price_DaoQi, A.Price_ShiChang,B.numStorageDate");
            strSql.Append(" FROM dbo.Dep_StorageInfo A INNER JOIN dbo.StorageTime B ON A.TimeID=B.ID");
            strSql.Append(" WHERE A.ID=" + Dep_SID);
            DataTable dt = SQLHelper.ExecuteDataTable(strSql.ToString());
            if (dt != null && dt.Rows.Count != 0)
            {


                DateTime StorageDate = Convert.ToDateTime(dt.Rows[0]["StorageDate"]);//存入日期
                DateTime InterestDate = Convert.ToDateTime(dt.Rows[0]["InterestDate"]);//上一次的取利息日期
                int numStorageDate = Convert.ToInt32(dt.Rows[0]["numStorageDate"]);//约定存储时间
                TimeSpan ts_Storage = DateTime.Now.Subtract(StorageDate);
                double Price_ShiChang = Convert.ToDouble(dt.Rows[0]["Price_ShiChang"]);//存入时的市场价
                double Price_DaoQi = Convert.ToDouble(dt.Rows[0]["Price_DaoQi"]);//到期价
                if (ts_Storage.TotalDays < numStorageDate)//定期存期未到期的情况
                {
                    numLiXi = 0;
                }
                else
                {
                    numLiXi = (Price_DaoQi - Price_ShiChang) * StorageNumber;
                }

            }
            return numLiXi;
        }


        #endregion 

        #region 存转销售利息计算和反算
        /// <summary>
        /// 获取村转销产生的利息
        /// </summary>
        /// <param name="objDep_SID">储户的存贮编号</param>
        /// <param name="StorageNumber">储户的存储数量</param>
        /// <returns></returns>
        public static double GetLiXi_Sell(object objDep_SID, double StorageNumber)
        {
            double numLiXi = 0;
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" select B.ISRegular,B.InterestType,A.StorageNumber,A.Price_ShiChang,A.StorageDate,B.numStorageDate");
            strSql.Append(" FROM dbo.Dep_StorageInfo A INNER JOIN dbo.StorageTime B ON A.TimeID=B.ID");
            strSql.Append(" WHERE A.ID=" + objDep_SID.ToString());

            DataTable dt = SQLHelper.ExecuteDataTable(strSql.ToString());
            //Add 0825 计算到存转销模模式的计算利息时间
            DateTime dtStorageTime = Convert.ToDateTime(dt.Rows[0]["StorageDate"]);
            int numLink = Convert.ToInt32(GetCompanyInfo()["strLink"]);
            //如何没到设置的存储期限，则在存储转销时不计算利息
            if (DateTime.Now.Subtract(dtStorageTime).TotalDays < numLink)
            {
                return 0;
            }
            //end Add
            if (dt != null && dt.Rows.Count != 0)
            {
                bool ISRegular = Convert.ToBoolean(dt.Rows[0]["ISRegular"]);//是否是定期类型
                int InterestType = Convert.ToInt32(dt.Rows[0]["InterestType"]);//利息计算方式
                double Price_ShiChang = Convert.ToInt32(dt.Rows[0]["Price_ShiChang"]);//存入时的市场价

                DateTime StorageDate = Convert.ToDateTime(dt.Rows[0]["StorageDate"]);//存入日期
                TimeSpan ts_Storage = DateTime.Now.Subtract(StorageDate);
                int numStorageDate = Convert.ToInt32(dt.Rows[0]["numStorageDate"]);//约定存储时间

                switch (InterestType)
                {
                    case 1://按月结息方式
                        if (ISRegular)//是定期（入股类型）
                        {
                            numLiXi = GetLiXi_RuGu(objDep_SID.ToString(), StorageNumber);

                        }
                        else
                        { //不是定期(付息类型)
                            numLiXi = GetLiXi_FuXi(objDep_SID.ToString(), StorageNumber);
                        }
                        break;
                    case 2://按市场价结息方式
                        numLiXi = GetLiXi_FenHong(objDep_SID.ToString(), StorageNumber);
                        break;
                    case 3:
                        numLiXi = GetLiXi_DingQi(objDep_SID.ToString(), StorageNumber);
                        break;
                }

            }

            return numLiXi;
        }
        #endregion



        #region 兑换利息计算和反算

        /// <summary>
        /// 获取利息
        /// </summary>
        /// <param name="objDep_SID">储户的存贮编号</param>
        /// <param name="StorageNumber">储户的存储数量</param>
        /// <returns></returns>
        public static double GetLiXi(object objDep_SID, double StorageNumber)
        {
            double numLiXi = 0;
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" select B.ISRegular,B.InterestType,A.StorageNumber,A.Price_ShiChang,A.StorageDate,B.numStorageDate");
            strSql.Append(" FROM dbo.Dep_StorageInfo A INNER JOIN dbo.StorageTime B ON A.TimeID=B.ID");
            strSql.Append(" WHERE A.ID=" + objDep_SID.ToString());

            DataTable dt = SQLHelper.ExecuteDataTable(strSql.ToString());
           
            if (dt != null && dt.Rows.Count != 0)
            {
                bool ISRegular = Convert.ToBoolean(dt.Rows[0]["ISRegular"]);//是否是定期类型
                int InterestType = Convert.ToInt32(dt.Rows[0]["InterestType"]);//利息计算方式
                double Price_ShiChang = Convert.ToInt32(dt.Rows[0]["Price_ShiChang"]);//存入时的市场价

                DateTime StorageDate = Convert.ToDateTime(dt.Rows[0]["StorageDate"]);//存入日期
                TimeSpan ts_Storage = DateTime.Now.Subtract(StorageDate);
                int numStorageDate = Convert.ToInt32(dt.Rows[0]["numStorageDate"]);//约定存储时间

                switch (InterestType)
                {
                    case 1://按月结息方式
                        if (ISRegular)//是定期（入股类型）
                        {
                            numLiXi = GetLiXi_RuGu(objDep_SID.ToString(), StorageNumber);

                        }
                        else
                        { //不是定期(付息类型)
                            numLiXi = GetLiXi_FuXi(objDep_SID.ToString(), StorageNumber);
                        }
                        break;
                    case 2://按市场价结息方式
                        numLiXi = GetLiXi_FenHong(objDep_SID.ToString(), StorageNumber);
                        break;
                    case 3:
                        numLiXi = GetLiXi_DingQi(objDep_SID.ToString(), StorageNumber);
                        break;
                }

            }

            return numLiXi;
        }

        /// <summary>
        /// 获取兑换时需要折合的原粮数量
        /// </summary>
        /// <param name="Dep_SID"></param>
        /// <param name="numMoney"></param>
        /// <returns></returns>
        public static double GetExVarietyCount(string Dep_SID, double numMoney)
        {
            double VarietyMark = 100;//标定的产品数量
            double MoneyMark = GetMoneyMark(Dep_SID, VarietyMark);
            double VarietyCount=(VarietyMark*numMoney)/MoneyMark;
            double Money_LiXi = GetLiXi(Dep_SID, VarietyCount);
            HttpContext.Current.Session["Ex_LiXi"] = Money_LiXi;//缓存兑换时产生的利息金额
            return VarietyCount;
        }


        /// <summary>
        /// 获取固定数量的产品的利息和金额总和
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="StorageNumber"></param>
        /// <returns></returns>
        public static string GetExPolicy(object obj, double StorageNumber)
        {
            string strReturn = "";
          
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" select B.ISRegular,B.InterestType,A.StorageNumber,A.Price_ShiChang,A.StorageDate,B.numStorageDate");
            strSql.Append(" FROM dbo.Dep_StorageInfo A INNER JOIN dbo.StorageTime B ON A.TimeID=B.ID");
            strSql.Append(" WHERE A.ID=" + obj.ToString());

            DataTable dt = SQLHelper.ExecuteDataTable(strSql.ToString());
            if (dt != null && dt.Rows.Count != 0)
            {
                bool ISRegular = Convert.ToBoolean(dt.Rows[0]["ISRegular"]);//是否是定期类型
                int InterestType = Convert.ToInt32(dt.Rows[0]["InterestType"]);//利息计算方式
                double Price_ShiChang = Convert.ToDouble(dt.Rows[0]["Price_ShiChang"]);//存入时的市场价

                DateTime StorageDate = Convert.ToDateTime(dt.Rows[0]["StorageDate"]);//存入日期
                TimeSpan ts_Storage = DateTime.Now.Subtract(StorageDate);
                int numStorageDate = Convert.ToInt32(dt.Rows[0]["numStorageDate"]);//约定存储时间
              
                switch (InterestType)
                {
                    case 1://按月结息方式
                        if (ISRegular)//是定期（入股类型）
                        {
                            strReturn = GetPolicy_RuGu(obj.ToString(), StorageNumber);

                        }
                        else
                        { //不是定期(付息类型)
                            strReturn = GetPolicy_FuXi(obj.ToString(), StorageNumber);
                        }
                        break;
                    case 2://按市场价结息方式
                        strReturn =GetPolicy_FenHong(obj.ToString(), StorageNumber);
                        break;
                    case 3:
                        strReturn = GetExPolicy_DingQi(obj.ToString(), StorageNumber);
                        break;
                }

            }

            return strReturn;
        }


        /// <summary>
        /// 获取固定数量的产品的利息和金额总和
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="StorageNumber"></param>
        /// <returns></returns>
        public static double GetMoneyMark(object obj, double StorageNumber)
        {
            double numLiXi = 0;
            double MoneyMark = 0;
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" select B.ISRegular,B.InterestType,A.StorageNumber,A.Price_ShiChang,A.StorageDate,B.numStorageDate");
            strSql.Append(" FROM dbo.Dep_StorageInfo A INNER JOIN dbo.StorageTime B ON A.TimeID=B.ID");
            strSql.Append(" WHERE A.ID=" + obj.ToString());

            DataTable dt = SQLHelper.ExecuteDataTable(strSql.ToString());
            if (dt != null && dt.Rows.Count != 0)
            {
                bool ISRegular = Convert.ToBoolean(dt.Rows[0]["ISRegular"]);//是否是定期类型
                int InterestType = Convert.ToInt32(dt.Rows[0]["InterestType"]);//利息计算方式
                double Price_ShiChang = Convert.ToDouble(dt.Rows[0]["Price_ShiChang"]);//存入时的市场价

                DateTime StorageDate = Convert.ToDateTime(dt.Rows[0]["StorageDate"]);//存入日期
                TimeSpan ts_Storage = DateTime.Now.Subtract(StorageDate);
                int numStorageDate = Convert.ToInt32(dt.Rows[0]["numStorageDate"]);//约定存储时间
                MoneyMark = StorageNumber * Price_ShiChang;
                switch (InterestType)
                {
                    case 1://按月结息方式
                        if (ISRegular)//是定期（入股类型）
                        {
                            numLiXi = GetLiXi_RuGu(obj.ToString(), StorageNumber);

                        }
                        else
                        { //不是定期(付息类型)
                            numLiXi = GetLiXi_FuXi(obj.ToString(), StorageNumber);
                        }
                        break;
                    case 2://按市场价结息方式
                        numLiXi = GetLiXi_FenHong(obj.ToString(), StorageNumber);
                        break;
                    case 3:
                        numLiXi = GetLiXi_DingQi(obj.ToString(), StorageNumber);
                        break;
                }

            }

            return numLiXi+MoneyMark;
        }

        /// <summary>
        /// 获取定期类型兑换时需要折合的原粮数量
        /// </summary>
        /// <param name="Dep_SID"></param>
        /// <param name="numMoney"></param>
        /// <returns></returns>
        public static double GetExVarietyCount_DingQi(string Dep_SID, double numMoney)
        {
            double VarietyCount = 0;//需要折合的原粮的数量
            double Money_YouHui = 0;//定期优惠的金额
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT A.StorageDate,A.InterestDate,A.CurrentRate, A.Price_DaoQi, A.Price_ShiChang,B.numStorageDate");
            strSql.Append(" FROM dbo.Dep_StorageInfo A INNER JOIN dbo.StorageTime B ON A.TimeID=B.ID");
            strSql.Append(" WHERE A.ID=" + Dep_SID);
            DataTable dt = SQLHelper.ExecuteDataTable(strSql.ToString());
            if (dt != null && dt.Rows.Count != 0)
            {
                DateTime StorageDate = Convert.ToDateTime(dt.Rows[0]["StorageDate"]);//存入日期
                DateTime InterestDate = Convert.ToDateTime(dt.Rows[0]["InterestDate"]);//上一次的取利息日期
                int numStorageDate = Convert.ToInt32(dt.Rows[0]["numStorageDate"]);//约定存储时间
                TimeSpan ts_Storage = DateTime.Now.Subtract(StorageDate);
                double Price_ShiChang = Convert.ToDouble(dt.Rows[0]["Price_ShiChang"]);//存入时的市场价
                double Price_DaoQi = Convert.ToDouble(dt.Rows[0]["Price_DaoQi"]);//到期价

                VarietyCount = numMoney / Price_ShiChang;//暂时设定折合原粮数量按照存入价格计算

                if (ts_Storage.TotalDays < numStorageDate)//定期存期未到期的情况
                {
                    //获取每个月的优惠兑换比例
                    StringBuilder strSqlProp = new StringBuilder();
                    strSqlProp.Append("  SELECT TOP 1 A.StorageNumberRaw,B.numExChangeProp");
                    strSqlProp.Append("   FROM dbo.Dep_StorageInfo A INNER JOIN dbo.StorageTime B ON A.TimeID=B.ID");
                    strSqlProp.Append("    WHERE A.ID="+Dep_SID);
                    DataTable dtProp = SQLHelper.ExecuteDataTable(strSqlProp.ToString());
                    if (dtProp == null || dtProp.Rows.Count == 0)//没有查询到优惠兑换比例
                    {
                        return VarietyCount;
                    }
                    double JieCun_Raw = Convert.ToDouble(dtProp.Rows[0]["StorageNumberRaw"]);
                    //double JieCun_Total = Convert.ToDouble(dt.Rows[0]["JieCun_Total"]);//已经发生的结存
                    double numExChangeProp = Convert.ToDouble(dtProp.Rows[0]["numExChangeProp"]);
                    double JieCun_Total = GetMonthJieCun_Total(Dep_SID);//已经发生的结存
                    //查询本月已经发生的结存
                    if (numExChangeProp <= 0)
                    {
                        return VarietyCount;//兑换利率为0；
                    }
                    double Exchange_Count = JieCun_Raw * numExChangeProp * 0.01;//最多允许兑换的数量
                    double SurPlue_Count = Exchange_Count - JieCun_Total;//剩余的可以优惠兑换的数量
                    if (SurPlue_Count <= 0)//优惠兑换比例已经用完
                    {
                        return VarietyCount;
                    }
                    if (SurPlue_Count * Price_DaoQi >= numMoney)//可优惠兑换数量大于兑换数量
                    {
                        VarietyCount = numMoney / Price_DaoQi;
                        Money_YouHui = (Price_DaoQi - Price_ShiChang) * VarietyCount;
                        HttpContext.Current.Session["Ex_YouHui"] = Money_YouHui;//缓存优惠金额
                        HttpContext.Current.Session["Ex_YouHui_Count"] = VarietyCount;//缓存此次定期优惠的数额
                    }
                    else
                    {
                        HttpContext.Current.Session["Ex_YouHui_Count"] = SurPlue_Count;//缓存此次定期优惠的数额
                        Money_YouHui = (Price_DaoQi - Price_ShiChang) * SurPlue_Count;
                        HttpContext.Current.Session["Ex_YouHui"] = Money_YouHui;//缓存优惠金额
                        VarietyCount = SurPlue_Count + (numMoney - SurPlue_Count * Price_DaoQi) / Price_ShiChang;
                    }

                }
                else
                {
                    VarietyCount = numMoney / Price_DaoQi;
                }
            }
            return VarietyCount;
        }

        /// <summary>
        /// 获取每个月的结存总额
        /// </summary>
        /// <param name="Dep_SID"></param>
        /// <returns></returns>
        static double GetMonthJieCun_Total(string Dep_SID)
        {
            string strYear=DateTime.Now.Year.ToString();
            string strMonth = DateTime.Now.Month.ToString();
            string strDateStart = strYear + "-" + strMonth + "-1";//每月的开始查询日期
            string strDateEnd = strYear + "-" + strMonth + "-31";//每月的结束查询日期
            if (strMonth == "4" || strMonth == "6" || strMonth == "9" || strMonth == "11") {
                 strDateEnd = strYear + "-" + strMonth + "-30";
            }
            if (strMonth == "2") {
                 strDateEnd = strYear + "-" + strMonth + "-28";
            }
            StringBuilder strSql = new StringBuilder();
            strSql.Append("  SELECT  SUM(VarietyCount)  FROM dbo.GoodExchange ");
            strSql.Append("  WHERE Dep_SID='"+Dep_SID+"'");
            strSql.Append("   AND dt_Exchange>='"+strDateStart+"' AND dt_Exchange<='"+strDateEnd+"'");
            strSql.Append("  ");
            object objSum = SQLHelper.ExecuteScalar(strSql.ToString());
            if (objSum == null || objSum.ToString() == "")
            {
                return 0;
            }
            else {
                return Convert.ToDouble(objSum);
            }
        }

        /// <summary>
        /// 获取定期类型兑换时的兑换政策
        /// </summary>
        /// <param name="Dep_SID"></param>
        /// <param name="numMoney"></param>
        /// <returns></returns>
        public static string GetExPolicy_DingQi(string Dep_SID, double numMoney)
        {
            string strReturn = "当前产品存期类型：定期,";//返回信息
            double VarietyCount = 0;//需要折合的原粮的数量
            double Money_YouHui = 0;//定期优惠的金额
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT A.StorageDate,A.InterestDate,A.CurrentRate, A.Price_DaoQi, A.Price_ShiChang,B.numStorageDate");
            strSql.Append(" FROM dbo.Dep_StorageInfo A INNER JOIN dbo.StorageTime B ON A.TimeID=B.ID");
            strSql.Append(" WHERE A.ID=" + Dep_SID);
            DataTable dt = SQLHelper.ExecuteDataTable(strSql.ToString());
            if (dt != null && dt.Rows.Count != 0)
            {
                DateTime StorageDate = Convert.ToDateTime(dt.Rows[0]["StorageDate"]);//存入日期
                DateTime InterestDate = Convert.ToDateTime(dt.Rows[0]["InterestDate"]);//上一次的取利息日期
                int numStorageDate = Convert.ToInt32(dt.Rows[0]["numStorageDate"]);//约定存储时间
                TimeSpan ts_Storage = DateTime.Now.Subtract(StorageDate);
                double Price_ShiChang = Convert.ToDouble(dt.Rows[0]["Price_ShiChang"]);//存入时的市场价
                double Price_DaoQi = Convert.ToDouble(dt.Rows[0]["Price_DaoQi"]);//到期价

                VarietyCount = numMoney / Price_ShiChang;//暂时设定折合原粮数量按照存入价格计算

                if (ts_Storage.TotalDays < numStorageDate)//定期存期未到期的情况
                {
                    strReturn += "未到期,";
                     //获取每个月的优惠兑换比例
                    StringBuilder strSqlProp = new StringBuilder();
                    strSqlProp.Append("  SELECT TOP 1 A.StorageNumberRaw,B.numExChangeProp");
                    strSqlProp.Append("   FROM dbo.Dep_StorageInfo A INNER JOIN dbo.StorageTime B ON A.TimeID=B.ID");
                    strSqlProp.Append("    WHERE A.ID="+Dep_SID);
                    DataTable dtProp = SQLHelper.ExecuteDataTable(strSqlProp.ToString());
                    if (dtProp == null || dtProp.Rows.Count == 0)//没有查询到优惠兑换比例
                    {
                        strReturn += "兑换价格：" + Price_ShiChang + ",无优惠兑换比例!";
                        return strReturn;
                    }
                    double JieCun_Raw = Convert.ToDouble(dtProp.Rows[0]["StorageNumberRaw"]);
                    //double JieCun_Total = Convert.ToDouble(dt.Rows[0]["JieCun_Total"]);//已经发生的结存
                    double numExChangeProp = Convert.ToDouble(dtProp.Rows[0]["numExChangeProp"]);
                  
                    double JieCun_Total = GetMonthJieCun_Total(Dep_SID);//已经发生的结存
                    //查询本月已经发生的结存
                    if (numExChangeProp <= 0)
                    {
                        strReturn += "兑换价格：" + Price_ShiChang + ",无优惠兑换比例!";
                        return strReturn;
                    }
                    double Exchange_Count = JieCun_Raw * numExChangeProp * 0.01;//最多允许兑换的数量
                    double SurPlue_Count = Exchange_Count - JieCun_Total;//剩余的可以优惠兑换的数量

                    if (JieCun_Total > Exchange_Count) {
                        JieCun_Total = Exchange_Count;
                        SurPlue_Count = 0;
                    }

                    strReturn += "市场价格：" + Price_ShiChang + ",兑换价格：" + Price_DaoQi + ",本月已优惠兑换数量：" + Math.Round(JieCun_Total, 2) + ",剩余可优惠兑换数量：" + Math.Round(SurPlue_Count, 2);
                    return strReturn;
                }
                else
                {
                    strReturn += "已到期,市场价格："+Price_ShiChang+"兑换价格："+Price_DaoQi;
                    
                }
            }
            return strReturn;
        }

        #endregion


        public static string GetCompanyName() {

            string str = "";
            object obj = SQLHelper.ExecuteScalar("  SELECT TOP 1 strName FROM dbo.BD_Company");
            if(obj!=null&&obj.ToString()!="")
            {
                str = obj.ToString();
            }
            return str;
        }

        /// <summary>
        /// 获取公司信息（strLink:存储期限；strRemark:价格政策）
        /// </summary>
        /// <returns></returns>
        public static DataRow GetCompanyInfo()
        {
            string strSql = "SELECT TOP 1 strName,strAddress,strLink,strPhone,strRemark,strPassword  FROM dbo.BD_Company";
            DataTable dt = SQLHelper.ExecuteDataTable(strSql);
            if (dt == null || dt.Rows.Count == 0)
            {
                return null;
            }
            else {
                return dt.Rows[0];
            }

        }

        public static bool  ISHQWB(object wbid)
        {
            object obj = SQLHelper.ExecuteScalar(" SELECT ISHQ FROM dbo.WB  WHERE ID="+wbid);
            return Convert.ToBoolean(obj);
        }

        /// <summary>
        /// 返回当前的网点权限设置
        /// </summary>
        /// <returns></returns>
        public static DataRow GetWBAuthority()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("  SELECT TOP 1 ID,Price_Merge,Price_Update,Price_PrintOnPingZheng,Price_PrintOnCunZhe,");
            strSql.Append("  Enable_PrintPingZheng,Enable_LimitMin,LimitMin,Enable_BackUpData,");
            strSql.Append("  IS_Extract,IS_StorageToSell,IS_QuZheng,IS_ZhuanCun,IS_TeJia,IS_YouHui,YouHuiProp,YouHuiLimit, VerifyType,Enable_Distance,ErrorLogin_Admin,ErrorLogin_User,ISPrintIDCard,ISPrintPhoneNo,InterestType");
            strSql.Append("  FROM dbo.WBAuthority");
            DataTable dt = SQLHelper.ExecuteDataTable(strSql.ToString());
            return dt.Rows[0];
        }

        /// <summary>
        /// 检测储户的密码是否正确
        /// </summary>
        /// <param name="AccountNumber">储户账号</param>
        /// <param name="Password">未经加密的密码</param>
        /// <returns></returns>
       public static bool CheckPassword(string AccountNumber,string Password)
        {
            bool flag = true;
            if (Convert.ToInt32(common.GetWBAuthority()["VerifyType"]) == 1)//需要输入密码验证 
            {
                //查询当前的密码与储户的密码是否符合
                string strPassword = SQLHelper.ExecuteScalar(" SELECT strPassword FROM dbo.Depositor WHERE AccountNumber='" + AccountNumber + "'").ToString();
                if (Fun.GetMD5_32(Password) == strPassword)
                {
                    flag = true;
                }
                else
                {
                    flag = false;
                }
            }
            else
            {
                flag = true;
            }
            return flag;

        }

       /// <summary>
       /// 检测储户的密码是否正确
       /// </summary>
       /// <param name="AccountNumber">储户账号</param>
       /// <param name="Password">未经加密的密码</param>
       /// <returns></returns>
       public static bool CheckPassword_Commune(string AccountNumber, string Password)
       {
           bool flag = true;
           if (Convert.ToInt32(common.GetWBAuthority()["VerifyType"]) == 1)//需要输入密码验证 
           {
               //查询当前的密码与储户的密码是否符合
               string strPassword = SQLHelper.ExecuteScalar(" SELECT strPassword FROM dbo.Commune WHERE AccountNumber='" + AccountNumber + "'").ToString();
               if (Fun.GetMD5_32(Password) == strPassword)
               {
                   flag = true;
               }
               else
               {
                   flag = false;
               }
           }
           else
           {
               flag = true;
           }
           return flag;

       }
    }
}